package edu.gdkm.dao;

import edu.gdkm.pojo.PersonalInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PersonalInfoDao {

    // 根据ID查询
    @Select("SELECT * FROM PersonalInfos WHERE info_id = #{infoId}")
    PersonalInfo selectById(Integer infoId);

    // 根据简历ID查询
    @Select("SELECT * FROM PersonalInfos WHERE resume_id = #{resumeId}")
    PersonalInfo selectByResumeId(Integer resumeId);

    // 查询所有
    @Select("SELECT * FROM PersonalInfos")
    List<PersonalInfo> selectAll();

    // 新增
    @Insert("INSERT INTO PersonalInfos(resume_id, full_name, professional_title, email, phone, location, website, summary) " +
            "VALUES(#{resumeId}, #{fullName}, #{professionalTitle}, #{email}, #{phone}, #{location}, #{website}, #{summary})")
    @Options(useGeneratedKeys = true, keyProperty = "infoId")
    int insert(PersonalInfo personalInfo);

    // 更新
    @Update("UPDATE PersonalInfos SET resume_id = #{resumeId}, full_name = #{fullName}, professional_title = #{professionalTitle}, " +
            "email = #{email}, phone = #{phone}, location = #{location}, website = #{website}, " +
            "summary = #{summary} WHERE info_id = #{infoId}")
    int update(PersonalInfo personalInfo);

    // 删除
    @Delete("DELETE FROM PersonalInfos WHERE info_id = #{infoId}")
    int delete(Integer infoId);
    
    // 根据简历ID删除
    @Delete("DELETE FROM PersonalInfos WHERE resume_id = #{resumeId}")
    int deleteByResumeId(Integer resumeId);
}
    